package com.nuvo.beans;

import com.nuvo.entities.Venta;
import com.nuvo.services.VentaService;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class VentaController implements Serializable {

    @EJB
    private VentaService ventaService;
    private Venta selected;

    public VentaController() {
    }

    public Venta getSelected() {
        if (selected == null) {
            selected = new Venta();
        }
        return selected;
    }

    public List<Venta> listado() {

        return ventaService.findAll();
    }

   
    
      public String index() {

        return "/venta/index";
    }
   
    
    public String nuevo(){
        selected = new Venta();
    return "/venta/new";
    }
    
     public String agregar() {
        ventaService.create(selected);
        return "/venta/index";
    } 
     
     public String guardar() {
        ventaService.edit(selected);
        return "/venta/index";
    }
     
      public String editar(int codigo) {
        selected = ventaService.find(codigo);
        return "/venta/edit";
    }
      
      public String eliminar(int codigo) {
        selected = ventaService.find(codigo);
        ventaService.remove(selected);
        return "/venta/index";
    } 
}
